package com.yuxi.task;

import com.yuxi.common.FileConfig;
import com.yuxi.common.FileUtil;
import com.yuxi.common.SkList;
import com.yuxi.common.StringUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.io.File;
import java.util.List;

/**
 * @author sunke
 * @version 1.0
 * @Description
 * @date 2023-11-19 20:30
 */

@EnableScheduling
@Slf4j
@Component
public class CleanHtmlTask {

    @Autowired
    private FileConfig fileConfig;

    @Scheduled(cron = "59 00 03 * * ?")
    public void run() {

        List<String> fileNameList = SkList.getInstance();
        FileUtil.getFolderFiles(new File(fileConfig.getHtmlPath()), "html", fileNameList, "");
        // FileUtil.deleteFolder(fileConfig.getHtmlPath());
        if (StringUtil.isNotObjEmpty(fileNameList)) {

            for (String fileName : fileNameList) {
                try {
                    FileUtil.deleteFile(fileConfig.getHtmlPath() + File.separator + fileName);
                } catch (Exception e) {

                }
            }

        }


    }
}
